# This is a basic workflow to help you get started with Actions

name: CI-CD

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]
  workflow_dispatch:
permissions:
  contents: read
  pages: write
  id-token: write
  
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
       - name: Checkout
         uses: actions/checkout@v4
       - name: Setup NodeJS
         uses: actions/setup-node@v4
         with:
          node-version: '20.11.0'
          cache: 'npm'

       - name: Install dependencies
         run: npm ci
       - name: Build
         run: npm run build

       - name: Upload build artifacts
         uses: actions/upload-artifact@v3
         with:
           name: build
           path: build
  github_pages:
    runs-on: ubuntu-latest
    needs: build
    steps:
       - name: Checkout
         uses: actions/checkout@v4

       - name: Setup NodeJS
         uses: actions/setup-node@v4
         with:
           node-version: '20.11.0'
           cache: 'npm'
       - name: Download build artifacts
         uses: actions/download-artifact@v3
         with:
             name: build
             path: build
       - name: Publish
         uses: peaceiris/actions-gh-pages@v4
         with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_branch: gh-pages
          publish_dir: ./build
